package com.nkzy.mapper;

import com.nkzy.pojo.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface AddressMapper {
     @Insert("INSERT INTO address (user_id, province, city, town, mobile, street, contact, is_default, notes, deleted) " +
            "VALUES (#{userId}, #{province}, #{city}, #{town}, #{mobile}, #{street}, #{contact}, #{isDefault}, #{notes}, #{deleted})")
     @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertAddress(Address address);

    @Delete("DELETE FROM address WHERE id = #{id}")
    void deleteAddressById(Long id);

    @Update("UPDATE address SET user_id = #{userId}, province = #{province}, city = #{city}, town = #{town}, " +
            "mobile = #{mobile}, street = #{street}, contact = #{contact}, is_default = #{isDefault}, " +
            "notes = #{notes}, deleted = #{deleted} WHERE id = #{id}")
    void updateAddress(Address address);

    @Select("SELECT * FROM address WHERE id = #{id}")
    Address selectAddressById(Long id);

    @Select("SELECT * FROM address WHERE user_id = #{userId}")
    List<Address> selectAddressesByUserId(Long userId);
}